package com.myblog.model.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 角色表
 * </p>
 *
 * @author 
 * @since 2022-09-03
 */
@Getter
@Setter
@TableName("sys_role")
@ApiModel(value = "SysRole对象", description = "角色表")
@ToString
public class SysRole implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("角色 ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty("角色名称")
    private String name;

    @ApiModelProperty("角色说明")
    private String remark;

    private LocalDateTime createDate;

    private LocalDateTime updateDate;

    @TableField(exist = false)
    private List<SysPermission> permissionList = Lists.newArrayList();

    @TableField(exist = false)
    private List<Long> perIds = Lists.newArrayList();

    public List<Long> getPerIds() {
        if(!CollectionUtils.isEmpty(permissionList)){
            perIds = Lists.newArrayList();
            permissionList.stream().forEach(SysPermission -> {
                perIds.add(SysPermission.getId());
            });
        }
        return perIds;
    }

}
